package com.cxs.handler;

import com.cxs.ex.BusinessException;
import com.cxs.model.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author: cxs
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public R<String> businessExHandler(BusinessException e) {
        log.error("=========业务异常==========", e);
        return R.fail(-1, e.getMessage());
    }

    @ExceptionHandler(RuntimeException.class)
    public R<String> runtimeExHandler(RuntimeException e) {
        log.error("===========RuntimeException=========", e);
        return R.fail(-1, "服务器出小差了");
    }


}
